#include<iostream>

const int N=1e5+10;
using namespace std;

int nums[N];
int leftflag(int n,int tar)
{
	int left=1,right=n;
	while(left<right)
	{
		int mid=left+(right-left)/2;
		if(nums[mid]>=tar)
		{
			right=mid;
		}
		else
		{
			left=mid+1;
		}
	}
	if(nums[left]<tar) return -1;
	return left;
}
int rightflag(int n,int tar)
{
	int left=1,right=n;
	while(left<right)
	{
		int mid=left+(right-left+1)/2;
		if(nums[mid]<=tar)
		{
			left=mid;
		}
		else
		{
			right=mid-1;
		}
	}
	if(nums[left]>tar) return -1;
	return left;
}
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++) cin>>nums[i];
	int q;cin>>q;
	while(q--)
	{
		int x,y;cin>>x>>y;
		//1.查找>=x和<=y
		//(1)>=x的最小值
		int left=leftflag(n,x);
		//(2)<=y的最大值
		int right=rightflag(n,y);
		if(left==-1||right==-1)
		{
			cout<<0<<endl;
		}
		else
		{
			cout<<right-left+1<<endl;
		}
	}
}